<template>
    <div class="c-info">
        <div class="c-info-messg">
            <div class="c-infon-messg-nun"><span v-if="messagenun != 0">{{messagenun}}</span></div>
            <img src="../../common/image/msg.png" alt="">
        </div>
        <div class="c-info-myinfon">
            <div class="c-infon-myimg">
                
                <img :src="datasinfo.userimg ==''? require('../../common/image/shanfenyuan.png') : datasinfo.userimg " alt="">
            </div>
            <div class="c-info-mycontent">
                <h1>{{datasinfo.username}}</h1>
                <p>{{datasinfo.userposition}}
                </p>
            </div>
            <div class="c-info-gd" @click="infoshow"><img src="../../common/image/xiajto.png" alt=""></div>

            <div class="c-infon-cz" v-if="infoshowis">
                <div class="c-infon-zl" @click="goinfonzl">个人资料</div>
                <div class="c-infon-outlogin" @click="outlogin">退出登录</div>
            </div>
        </div>
    </div>
</template>
<script>
import { ref,reactive} from 'vue-demi'
import { useStore } from 'vuex'
import {getWorkMessageNum,getUserInfo} from '../../api/api'
import { ElMessage } from 'element-plus'
import 'element-plus/theme-chalk/el-loading.css';
import 'element-plus/theme-chalk/el-message.css';
import { useRouter,useRoute} from 'vue-router'

export default {
    
    setup() {
        const router = useRouter()
     const store = useStore()
     
     const messagenun= ref(0)
     const datasinfo=reactive({
        username:'',
        userimg:'',
        userposition:'',
     })
     
     const getinfonmessage= function(){
        
        getWorkMessageNum({userid:localStorage.getItem('userinfoId')}).then((res)=>{
        //   context.commit('mutNameChage', res.messageNum);
        console.log(res)
         messagenun.value=res.messageNum

        })
        return getinfonmessage

     }
    //  持续获取消息
    setInterval(getinfonmessage(),30000)
     getUserInfo({userid:localStorage.getItem('userinfoId')}).then(res=>{
        console.log('getUserInfo',res)
        datasinfo.username=res.user.name
        datasinfo.userposition=res.user.position
        datasinfo.userimg=res.user.wxHeadImage
        store.commit('setidentity',res.user.identity)
        console.log( datasinfo.userimg)
     }).catch (res=>{

     })
    // 
    const goinfonzl= ()=>{

    }
    const infoshowis=ref(false)
    const infoshow = ()=>{
        infoshowis.value = !infoshowis.value
    }
     const outlogin= ()=>{
        localStorage.removeItem('userinfoId')
         router.push({path :'/login', query:{
            redirect: router.currentRoute.value.fullPath
          }})


    }
     return{
        infoshowis,
        infoshow,
        outlogin,
        goinfonzl,
        messagenun,
        datasinfo,

     }
        
    },
}
</script>
<style scoped>
.c-info-messg{
    width: 64px;
    height: 64px;
    margin-right: 60px;
    position: relative;
}
.c-infon-messg-nun{
    position: absolute;
    top: 8px;
    left: 32px;
    font-size: 12px;
}
.c-infon-messg-nun span{
    width: 37px;
    height: 24px;
    color: white;
    background: #FF5300;
    display: block;
    border-radius: 100px;
    text-align: center;
    line-height: 24px;
}

.c-info-messg img{
    width: 64px;
}
.c-info{
    display: flex;
    justify-content: center;
    align-items: center;
}
.c-info-myinfon{
    width: 264px;
height: 64px;
background: #FFFFFF;
border-radius: 32px;
display: flex;
justify-content: space-between;
align-items: center;
position: relative;
}
.c-info-myinfon .c-infon-myimg{
  position: absolute;
  width: 80px;
  height: 80px; 
  top: -8px;
  left: -40px;
  border-radius: 100%;
  overflow: hidden;
}
.c-info-myinfon .c-infon-myimg img{
  width: 80px;
}
.c-info-mycontent{
    margin-right: 16px;
    margin-left: 50px;
}
.c-info-mycontent h1{
/* width: 56px; */
height: 28px;
font-size: 18px;
font-weight: bold;
color: #020113;
line-height: 28px;    
}
.c-info-mycontent p{
    /* width: 117px; */
height: 22px;
font-size: 14px;
font-weight: 400;
color: #020113;
line-height: 22px;
}
.c-info-gd{
    margin-right: 10px;
    width: 48px;
    height: 48px;

}
.c-info-gd img{
    width: 48px;
    height: 48px;
}
.c-infon-cz{
    position: absolute;
    width: 240px;
    height: 134px;
    background: #FFFFFF;
    box-shadow: 0px 8px 48px 0px rgba(1,7,19,0.1500);
    /* display: flex;
    align-items: center;
    white-space: pre-wrap; */
    bottom: -134px;
    right: 0px;
    z-index: 500;
}
.c-infon-zl{
    width: 240px;
    font-size: 24px;
    font-weight: 400;
    color: #000000;
    line-height: 66px;
    border-bottom: 2px solid #F5F5F6;
    text-align: center;
    height: auto;
}
.c-infon-outlogin{
    width: 240px;
    height: auto;
    font-size: 24px;
    font-weight: 400;
    color: #000000;
    line-height: 66px;
    text-align: center;
}

</style>